package com.symaster.common.geom.nest4j.data;

import com.symaster.common.geom.entity.Point;

import static com.symaster.common.geom.nest4j.util.Config.CLIIPER_SCALE;

/**
 * @author yisa
 */
public class Segment {
    public double x;
    public double y;

    public boolean marked = false;
    public Segment start;
    public Segment end;


    public Segment() {
    }

    public Segment(Segment srcSeg) {
        this.x = srcSeg.x;
        this.y = srcSeg.y;
    }


    public Segment(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public Segment(double x, double y) {
        int Ix = (int) (x * CLIIPER_SCALE);
        int Iy = (int) (y * CLIIPER_SCALE);

        this.x = (double) Ix / CLIIPER_SCALE;
        this.y = (double) Iy / CLIIPER_SCALE;
    }

    public Segment(double x, double y, Segment start, Segment end) {
        this.x = x;
        this.y = y;
        this.start = start;
        this.end = end;
    }

    @Override
    public boolean equals(Object obj) {
        Segment s = (Segment) obj;
        return x == s.x && y == s.y;
    }

    @Override
    public String toString() {
        return "x = " + x + ", y = " + y;
    }

    public boolean isMarked() {
        return marked;
    }

    public void setMarked(boolean marked) {
        this.marked = marked;
    }

    public Segment getStart() {
        return start;
    }

    public void setStart(Segment start) {
        this.start = start;
    }

    public Segment getEnd() {
        return end;
    }

    public void setEnd(Segment end) {
        this.end = end;
    }

    public double getX() {
        return x;
    }

    public void setX(double x) {
        int lx = (int) (x * CLIIPER_SCALE);
        this.x = lx * 1.0 / CLIIPER_SCALE;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        int ly = (int) (y * CLIIPER_SCALE);
        this.y = ly * 1.0 / CLIIPER_SCALE;
    }

    public Point toPoint() {
        return new Point(getX(), getY());
    }
}
